# -*- coding: utf-8 -*-

__author__ = 'bilibili'

import types
import copy
from spot_excel_reader import spot_excel_reader
from spot_config import spot_config
from spot_excel_analyzer_base import spot_excel_analyzer_base

class spot_TSL_analyzer(spot_excel_analyzer_base):
    # FUNCTION: __init__(self, string)
    #   the constructor of the class spot_TSL_analyzer
    # ARGS:
    #   @config_name: json config file name
    def __init__(self, config_name='TSLnew.config.json'):
        spot_excel_analyzer_base.__init__(self, config_name)

    def fetch_key(self, in_dict):
        return in_dict['THEATER']

    def new_value(self, in_dict):
        return in_dict

    def value_operation(self, key, in_dict):
        pass

    def post_build_operation(self):
        pass

    def customized_calculation(self, arg_list):
        pass

    # FUNCTION: get_level_2_info(self, string, string)
    #   get the raw dictionary
    # ARGS:
    #   @key_1: first key
    #   &key_2: second key
    # RETURN:
    #   string: the dictionary to the key_1 and key_2
    def get_level_2_info(self, key_1, key_2):
        if key_1 == '':
            res = 0
            for (d, x) in self.res_dict.items():
                res += x[key_2]
            return res / len(self.res_dict)
        return self.res_dict[key_1][key_2]

def test_spot_TSL_analyzer():
    analyzer = spot_TSL_analyzer()
    analyzer.build_whole_table()
    print analyzer.get_theater_info('EU')['Q2_REV_PM1_ATTAIN_PCT']

if __name__ == '__main__':
    test_spot_TSL_analyzer()
